function pagination_home(){
	$("#pagination_previous_span").html("");
	$("#pagination_next_span").html("<a title='next page' class='next' href='#' onclick='pagination_next()'><span>Next</span></a> <a title='last page' class='last' href='#' onclick='pagination_last()'><span>Last</span></a>");
	post_page("1");
}
function pagination_previous(){
	var p=parseInt($("#pagination_pages").val())-parseInt(1);
	if(p<1){
		$("#pagination_previous_span").html("");
		p=1;
	}else{
		if(p<=1)
			$("#pagination_previous_span").html("");
		post_page(p);
		$("#pagination_next_span").html("<a title='next page' class='next' href='#' onclick='pagination_next()'><span>Next</span></a> <a title='last page' class='last' href='#' onclick='pagination_last()'><span>Last</span></a>");
	}
}
function pagination_next(){
	
	var p=parseInt($("#pagination_pages").val())+parseInt(1);
	var l=parseInt($("#pagination_num_pages").val());	
	if(p>l){
		$("#pagination_next_span").html("");
		p=l;
	}else{
		if(p>=l)
			$("#pagination_next_span").html("");
		post_page(p);	
		$("#pagination_previous_span").html("<a title='first page' class='first' href='#' onclick='pagination_home()'><span>First</span></a> <a title='previous page' class='previous' href='#' onclick='pagination_previous()'><span>Previous</span></a>");
	}
}
function pagination_last(){
	$("#pagination_next_span").html("");
	$("#pagination_previous_span").html("<a title='first page' class='first' href='#' onclick='pagination_home()'><span>First</span></a> <a title='previous page' class='previous' href='#' onclick='pagination_previous()'><span>Previous</span></a>");
	var p=$("#pagination_num_pages").val();
	post_page(p);
}

function post_page(p){
	$("#select_client").removeAttr("checked");
	var psv=$("#pagination_select_value").val();	
	var pcs="";
	if(psv=="")
		pcs="";
	else
		pcs=psv;
	$("#page_content").find(':checkbox').each(function(){
		if($(this).attr("checked")){
			if(pcs=="")
				pcs=$(this).val();
			else
				pcs+=","+$(this).val();
		}else{
			psv.replace($(this).val()+",","");
		}
	});
	$("#pagination_select_value").val(pcs);
	$.post($("#pagination_url").val(),{
		query_condition:$("#pagination_query_condition").val(),
		sequence: $("#pagination_sequence_value").val(),
		page:p
	},
	function(result){    
		if(result){    
			$("#page_content").html(result); 
			$("#pagination_pages").val(p);
			var post_psv=$("#pagination_select_value").val();	
			$("#page_content").find(':checkbox').each(function(){
				if(post_psv.indexOf($(this).val()+",")>=0)
					$(this).attr("checked","true");
			});
		}else{
			alert("出錯");
		}
	}); 
}